package com.niuwa.p2p.core.mvc.entity;

import java.io.Serializable;
import java.util.List;

public class PageBean<T> implements Serializable {

	private static final long serialVersionUID = -3953772369286066983L;

	public static final String PAGESIZE = "page";
	public static final String PAGENUM = "rows";

	/** 总条数 */
	private long total;
	
	/** 页大小 ,当前页结果*/
	private Object rows;
	
	private long items;

	/** 当前页 */
	private long page;

	/** 总页数 */
	private long records;


	public static final Long DEFAULT_PAGE_SIZE = Long.valueOf(10);
	public static final Long PAGE_SIZE_15 = Long.valueOf(15);
	public static final Long PAGE_SIZE_20 = Long.valueOf(20);
	public static final Long PAGE_SIZE_30 = Long.valueOf(30);
	public static final Long PAGE_SIZE_50 = Long.valueOf(50);

	public PageBean() {
		this(null, 1, 1, DEFAULT_PAGE_SIZE);
	}

	public PageBean(long recordTotal) {
		this(null, 1, recordTotal, DEFAULT_PAGE_SIZE);
	}

	public PageBean(long recordTotal, long pageSize) {
		this(null, 1, recordTotal, pageSize);
	}

	public PageBean(List<T> rows, long pageNum, long recordTotal,
			long pageSize) {
		this.rows = rows;
		this.items = pageSize;
		setPage(pageNum);
		setTotal(recordTotal);

	}


	public void setItems(long items) {
		this.items = items;
	}

	public void setPage(long page) {
		if (page < 1) {
			this.page = 1;
		} else {
			this.page = page;
		}
	}

	public void setTotal(long total) {
		this.total = total;
		if (total % items == 0) {
			total = total / items;
		} else {
			total = total / items + 1;
		}
	}

	/**
	 * 获取当前页数（从1开始）
	 * 
	 * @return
	 */
	public long getPage() {
		return page;
	}

	/**
	 * 获取总记录数
	 * 
	 * @return
	 */
	public long getRecords() {
		return records;
	}

	public Object getRows() {
		return rows;
	}

	public void setRows(Object rows) {
		this.rows = rows;
	}

	public static Long getDefaultPageSize() {
		return DEFAULT_PAGE_SIZE;
	}

	/**
	 * 总页数
	 * 
	 * @return
	 */
	public long getTotal() {
		return total;
	}

	public void setRecords(long records) {
		this.records = records;
	}

	public long getItems() {
		return items;
	}

}
